package com.xinsoft.controller.basic;

import com.xinsoft.aop.ano.SysLog;
import com.xinsoft.common.BusinessType;
import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysTruckPageParam;
import com.xinsoft.entity.po.SysTruck;
import com.xinsoft.service.SysTruckService;
import com.xinsoft.validator.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName SysTruckController
 * @Description 车辆管理控制层
 * @Author xuhb
 * @Date 2023-5-17 09:51:32
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/truck")
@Api(value = "SysTruckController", tags = {"车辆管理控制层"})
public class SysTruckController {
    @Autowired
    private SysTruckService sysTruckService;



    /**
     * @return com.xinsoft.common.Response<?>
     * @Author xuhb
     * @Description 车辆管理-新增
     * @Date 2023/5/17 9:57
     * @params truck
     **/
    @SysLog(title = "车辆管理-新增", businessType = BusinessType.INSERT)
    @ApiOperation("新增")
    @PostMapping("/add")
    public Response<?> add(@RequestBody SysTruck truck) {
        // 参数校验
        ValidatorUtils.validateEntity(truck);
        String msg = sysTruckService.saveTruck(truck);
        if(StringUtils.isEmpty(msg)){
            return Response.succeed();
        }else {
            return Response.fail(msg);
        }

    }

    /**
     * @return com.xinsoft.common.Response<?>
     * @Author xuhb
     * @Description 更新
     * @Date 2023/5/17 9:57
     * @params truck
     **/
    @ApiOperation("更新")
    @SysLog(title = "车辆管理-编辑", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Response<?> edit(@RequestBody SysTruck truck) {
        // 参数校验
        ValidatorUtils.validateEntity(truck);
        String msg = sysTruckService.updateTruck(truck);
        if(StringUtils.isEmpty(msg)){
            return Response.succeed();
        }else {
            return Response.fail(msg);
        }
    }


    /**
     * @return com.xinsoft.common.Response<?>
     * @Author xuhb
     * @Description 获取详情
     * @Date 2023/5/19 9:57
     * @params param
     **/
    @ApiOperation("获取分页信息")
    @PostMapping("/listPage")
    public Response<?> listPage(@Valid @RequestBody SysTruckPageParam param) {
        return Response.succeed(sysTruckService.listPageTruck(param),"查询成功");
    }

    /**
     * @return com.xinsoft.common.Response<?>
     * @Author xuhb
     * @Description 删除
     * @Date 2023/5/12 9:20
     * @params ids
     **/
    @ApiOperation("删除")
    @SysLog(title = "车辆管理-删除", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public Response<?> del(@RequestBody List<Integer> ids) {
        sysTruckService.removeByIds(ids);
        return Response.succeed();
    }






}
